# $Id: PKGBUILD 88839 2013-04-23 17:42:26Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Michal Krenek <mikos@sg1.cz>

pkgbase=boinc
pkgname=(boinc boinc-nox)
pkgver=7.0.65
_tag="client_release/7.0/$pkgver"
pkgrel=1
arch=('i686' 'x86_64')
url="http://boinc.berkeley.edu/"
license=('LGPL')
makedepends=('libxslt' 'perl-xml-sax' 'git' 'libxss' 'libnotify' 'wxgtk' 'sqlite3' 'curl' 'inetutils')
options=('!libtool')
install=$pkgbase.install
source=("git://boinc.berkeley.edu/boinc-v2.git#tag=$_tag"
	boinc.bash
	boinc.desktop
	boinc.service
	boinc-AM_CONDITIONAL.patch)

build() {
  msg "Starting make..."
  
  # Build boinc
  rm -rf "$srcdir/$pkgbase-build"
  git clone "$srcdir/$pkgbase-v2" "$srcdir/$pkgbase-build"
  cd "$srcdir/$pkgbase-build"
  git checkout "$_tag"

  patch -Np1 -i "${srcdir}/boinc-AM_CONDITIONAL.patch"

  ./_autosetup

  LDFLAGS='-lX11' ./configure \
    --prefix=/usr \
    --disable-server \
    --enable-unicode \
    --with-ssl \
    --enable-dynamic-client-linkage \
    --with-wxdir=/usr/lib \
    --with-wx-config=$(which wx-config) \
    --disable-static \
    --enable-client \
    --enable-manager \
    --with-x
  make

  # Build boinc-nox
  rm -rf "$srcdir/$pkgbase-nox-build"
  git clone "$srcdir/$pkgbase-v2" "$srcdir/$pkgbase-nox-build"
  cd "$srcdir/$pkgbase-nox-build"
  git checkout "$_tag"

  patch -Np1 -i "${srcdir}/boinc-AM_CONDITIONAL.patch"

  ./_autosetup

  PKG_CONFIG="$(which pkg-config)" ./configure \
    --prefix=/usr \
    --disable-server \
    --enable-unicode \
    --with-ssl \
    --enable-dynamic-client-linkage \
    --disable-xss \
    --disable-static \
    --enable-client \
    --disable-manager \
    --without-wxdir \
    --without-x
  make
}

package_boinc() {
  pkgdesc="Berkeley Open Infrastructure for Network Computing for desktop"
  depends=("libxss" "libnotify" "wxgtk" "curl" "sqlite3")

  cd "$srcdir/$pkgbase-build"

  make DESTDIR="$pkgdir" install

#install systemd unit
  install -Dm644 "${srcdir}/$pkgbase.service" "${pkgdir}/usr/lib/systemd/system/$pkgbase.service"

#install bash-completion
  install -Dm644 "${srcdir}/$pkgbase.bash" "${pkgdir}/usr/share/bash-completion/completions/$pkgbase"

#install .desktop File
  install -Dm644 "${srcdir}/${pkgbase}.desktop" "${pkgdir}/usr/share/applications/${pkgbase}.desktop"

#install icons
  install -Dm644 "${srcdir}/${pkgbase}-build/clientgui/res/boincmgr.48x48.png" "${pkgdir}/usr/share/pixmaps/$pkgbase.png"

#killing /etc/init.d directory
  rm -rf ${pkgdir}/etc/init.d
}

package_boinc-nox() {
  pkgdesc="Berkeley Open Infrastructure for Network Computing for desktop without Xorg dependencies"
  depends=("curl")
  provides=("boinc")
  conflicts=("boinc")

  cd "$srcdir/$pkgbase-nox-build"

  make DESTDIR="$pkgdir" install

#install systemd unit
  install -Dm644 "${srcdir}/$pkgbase.service" "${pkgdir}/usr/lib/systemd/system/$pkgbase.service"

#install bash-completion
  install -Dm644 "${srcdir}/$pkgbase.bash" "${pkgdir}/usr/share/bash-completion/completions/$pkgbase"

#killing /etc/init.d directory
  rm -rf ${pkgdir}/etc/init.d
}

md5sums=('SKIP'
         '4d00e1aa4090a3f51feb20f5a541b9ee'
         'db62de2f08117e6379a3c613b58fa7ff'
         '3d5cbab785cc8b004661b17c65883fd5'
         'e27047518dec54d4db38816487a28661')
